//
//  MTLuckyItemView.swift
//  MT
//
//  Created by ooops on 2020/1/21.
//  Copyright © 2020 张强. All rights reserved.
//

import UIKit
import MTCategory

class MTLuckyItemView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.theme.main
        setupUI()
        makeConstraint()
    }
    
    convenience init(money: String, description: String) {
        self.init(frame: .zero)
        self.moneyLabel.text = money
        self.tipLabel.text = description
    }
    
    func hiddenMaskView(isHidden: Bool) {
        masksView.isHidden = isHidden
    }
    
    func hiddenHoverMaskView(isHidden: Bool) {
        hoverMasksView.isHidden = isHidden
    }
    
    lazy var masksView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(hex: 0x000000, alpha: 0.5)
        v.isHidden = true
        return v
    }()
    
    lazy var hoverMasksView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor(hex: 0x000000, alpha: 0.5)
        v.isHidden = true
        return v
    }()
    
    lazy var bgImageView: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "hongbao"))
        return imageV
    }()
    
    lazy var moneyLabel: UILabel = {
        let l = UILabel()
        l.font = UIFont(name: "Arial Rounded MT Bold", size: 38)
        l.textColor = UIColor.theme.main
        l.textAlignment = .center
//        l.text = "100"
        l.adjustsFontSizeToFitWidth = true
        l.baselineAdjustment = .alignCenters
        return l
    }()
    
    lazy var tipLabel: UILabel = {
        let l = UILabel()
        l.font = PingFangSCRegularFont(14)
        l.textColor = UIColor.theme.main
        l.text = "钻石"
        l.textAlignment = .center
        l.adjustsFontSizeToFitWidth = true
        return l
    }()
    
    private func setupUI() {
        addSubview(bgImageView)
        bgImageView.addSubview(moneyLabel)
        bgImageView.addSubview(tipLabel)
        addSubview(hoverMasksView)
        addSubview(masksView)
    }
    
    private func makeConstraint() {
        
        bgImageView.snp.makeConstraints { (make) in
            make.edges.equalTo(UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
        }
        
        moneyLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(8)
            make.centerX.equalToSuperview()
            make.left.equalToSuperview().offset(2)
            make.right.equalToSuperview().offset(-2)
//            make.height.equalTo(40)
            make.bottom.equalTo(tipLabel.snp.top)
        }
        
        tipLabel.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.left.right.equalToSuperview()
            make.height.equalTo(20)
            make.bottom.equalToSuperview().offset(-8)
        }
        
        masksView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        hoverMasksView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }


}
